<%@ page language="java" import="java.util.*" pageEncoding="utf-8" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>

<%
    String path = request.getContextPath();
    String basePath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort() + path + "/";
%>
<!DOCTYPE html>
<html>

<head>
    <meta charset="UTF-8">
    <title>欢迎页面-X-admin2.0</title>
    <base href="<%=basePath%>"/>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport"
          content="width=device-width,user-scalable=yes, minimum-scale=0.4, initial-scale=0.8,target-densitydpi=low-dpi"/>
    <link rel="shortcut icon" href="statics/images/favicon.ico" type="image/x-icon"/>
    <link rel="stylesheet" href="statics/css/font.css">
    <link rel="stylesheet" href="statics/css/xadmin.css">
    <script src="statics/js/jquery-1.12.4.js"></script>
    <script src="statics/layui.js" charset="UTF-8"></script>
    <script type="text/javascript" src="statics/js/xadmins.js"></script>
    <!-- 让IE8/9支持媒体查询，从而兼容栅格 -->
    <!--[if lt IE 9]>
  <!--  <script src="https://cdn.staticfile.org/html5shiv/r29/html5.min.js"></script>
    <script src="https://cdn.staticfile.org/respond.js/1.4.2/respond.min.js"></script>-->

</head>
<body style="text-align: center;margin:0 auto;">
<div class="x-body" style="text-align: center;margin:0 auto;width: 600px">

    <form class="layui-form" style="width: 800px" enctype="multipart/form-data" method="post">

        <div class="layui-form-item" style="width: 800px">
            <label for="username" class="layui-form-label">
                <span class="x-red">*</span>软件名称
            </label>
            <div class="layui-input-inline" style="width: 500px">
                <input type="text" id="softwareName" name="softwareName" value="${appstate.softwareName }"
                       autocomplete="off" class="layui-input" style="width: 500px">
            </div>
        </div>
        <div class="layui-form-item">
            <label for="username" class="layui-form-label">
                <span class="x-red">*</span>apk名称
            </label>
            <div class="layui-input-inline" style="width: 500px">
                <input type="text" id="APKName" name="APKName" value="${appstate.APKName }"
                       autocomplete="off" class="layui-input" style="width: 500px">
            </div>
        </div>
        <div class="layui-form-item">
            <label for="phone" class="layui-form-label">
                <span class="x-red">*</span>支持ROM
            </label>
            <div class="layui-input-inline" style="width: 500px">
                <input type="text" id="supportROM" name="supportROM" value="${appstate.supportROM }"
                       autocomplete="off" class="layui-input" style="width: 500px">
            </div>
        </div>
        <div class="layui-form-item">
            <label for="username" class="layui-form-label">
                <span class="x-red">*</span>界面语言
            </label>
            <div class="layui-input-inline" style="width: 500px">
                <input type="text" id="interfaceLanguage" name="interfaceLanguage" required=""
                       value="${appstate.interfaceLanguage }"
                       autocomplete="off" class="layui-input" style="width: 500px">
            </div>
        </div>
        <div class="layui-form-item">
            <label for="username" class="layui-form-label">
                <span class="x-red">*</span>软件大小
            </label>
            <div class="layui-input-inline" style="width: 500px">
                <input type="text" id="softwareSize" name="softwareSize" required="" value="${appstate.softwareSize }"
                       autocomplete="off" class="layui-input" style="width: 500px">
            </div>
        </div>
        <div class="layui-form-item">
            <label for="username" class="layui-form-label">
                <span class="x-red">*</span>下载次数
            </label>
            <div class="layui-input-inline" style="width: 500px">
                <input type="text" id="downloads" name="downloads" value="${appstate.downloads }"
                       autocomplete="off" class="layui-input" style="width: 500px">
            </div>
        </div>
        <div class="layui-form-item">
            <label for="username" class="layui-form-label">
                <span class="x-red">*</span>所属平台
            </label>
            <div class="layui-input-inline" style="width: 500px">
                <select name="flatformId"
                        lay-filter="flatformId">
                    <option value="0" selected="">-请选择-</option>
                    <option value="1">手机</option>
                    <option value="2">平板</option>
                    <option value="3">通用</option>
                </select>
            </div>
        </div>
        <div class="layui-form-item">
            <label for="username" class="layui-form-label">
                <span class="x-red">*</span>一级分类
            </label>
            <div class="layui-input-inline" style="width: 500px">
                <select name="cate1"
                        lay-filter="cate1">
                    <option value="0" selected="">-请选择-</option>
                    <option value="1">全部应用</option>
                    <option value="2">全部游戏</option>
                </select>
            </div>
        </div>

        <div class="layui-form-item">
            <label for="username" class="layui-form-label">
                <span class="x-red">*</span>二级分类
            </label>
            <div class="layui-input-inline" style="width: 500px">
                <select name="cate2" lay-filter="cate2">
                    <option value="0" selected="">-请选择-</option>
                </select>
            </div>
        </div>
        <div class="layui-form-item">
            <label for="username" class="layui-form-label">
                <span class="x-red">*</span>三级分类
            </label>
            <div class="layui-input-inline" style="width: 500px">
                <select name="cate3" lay-filter="aihao">
                    <option value="0" selected="">-请选择-</option>
                </select>
            </div>
        </div>
        <div class="layui-form-item">
            <label for="username" class="layui-form-label">
                <span class="x-red">*</span>app状态
            </label>
            <div class="layui-input-inline" style="width: 500px">
                <select name="states" lay-filter="sta">
                <option value="0" selected="">-请选择-</option>
                <option value="1">待审核</option>
                <option value="2">审核通过</option>
                <option value="3">审核未通过</option>
                <option value="4">已上架</option>
                <option value="5">已下架</option>
                </select>
            </div>
        </div>
        <div class="layui-form-item layui-form-text">
            <label for="desc" class="layui-form-label">
                应用简介
            </label>
            <div class="layui-input-block">
                <textarea placeholder="请输入内容" id="desc" name="desc" class="layui-textarea">${appstate.infos }</textarea>
            </div>

        </div>
        <div class="layui-form-item">
            <label for="L_repass" class="layui-form-label">
            </label>
            <button class="layui-btn" lay-filter="add" lay-submit="">
                保存
            </button>
            <button class="layui-btn" lay-filter="back" lay-submit="">
                重置
            </button>
        </div>
    </form>
</div>
<script>
    function reloads() {
        window.parent.location.reload();
    }
    layui.use(['form', 'layer'], function () {
        $ = layui.jquery;
        var form = layui.form
            , layer = layui.layer;
        form.on('select(back)', function (data) {
            reloads();
            return false;
        });
        form.on('select(cate1)', function (data) {
            var cate1 = $('select[name=cate1]').val();
            if (cate1 == 0) {
                $('select[name=cate2]').html('<option value=0>-请选择-</option>');
                $('select[name=cate3]').html('<option value=0>-请选择-</option>');
                form.render();
            } else {
                $.ajax({
                    url: "/AppManageSys/app/selectCategorys?parentId=" + cate1,
                    data: "parentId=" + cate1,
                    dataType: "JSON",
                    type: "POST",
                    success: function (data) {
                        if (data != null) {
                            $('select[name=cate2]').html('');
                            $('select[name=cate2]').html('<option value=0>-请选择-</option>');
                            for (var i = 0; i < data.length; i++) {
                                var option = $('<option value=' + data[i].id + '>' + data[i].categoryName + '</option>');
                                $('select[name=cate2]').append(option);
                                //$('select[lay-filter=aihao]').append('你好');
                            }
                            form.render();
                        }
                    }
                });
            }

        });


        form.on('select(cate2)', function (data) {
            var cate2 = $('select[name=cate2]').val();
            if (cate2 == '0') {
                $("select[name='cate3']").html('<option value=0 >-请选择-</option>');
                form.render();
            } else {
                $.ajax({
                    url: "/AppManageSys/app/selectCategorys?parentId=" + cate2,
                    data: "parentId=" + cate2,
                    dataType: "JSON",
                    type: "POST",
                    success: function (data) {
                        if (data != null) {
                            $('select[name=cate3]').html('');
                            $('select[name=cate3]').html('<option value=0>-请选择-</option>');
                            for (var i = 0; i < data.length; i++) {
                                var option = $('<option value=' + data[i].id + '>' + data[i].categoryName + '</option>');
                                $('select[name=cate3]').append(option);
                                //$('select[lay-filter=aihao]').append('你好');
                            }
                            form.render();
                        }
                    }

                });
            }

        });
        form.on('submit(add)', function (data) {
            var index = layer.msg('数据保存中', {icon: 16, time: false, shade: 0.5});
            var arr = $('form').serialize();
            /**
             var formData=new FormData();
             var softwareName=$("#softwareName").val();
             var softwareSize=$("#softwareSize").val();
             var APKName=$("#APKName").val();
             var supportROM=$("#supportROM").val();
             var downloads=$("#downloads").val();
             var cate1=$("select[name='cate1']").val();
             var cate2=$("select[name='cate2']").val();
             var cate3=$("select[name='cate3']").val();
             var desc=$("#desc").val();
             var fileName=document.getElementById("fileName").files[0];
             var states=$("select[name='states']").val();
             formData.append("softwareName",softwareName);
             formData.append("softwareSize",softwareSize);
             formData.append("APKName",APKName);
             formData.append("supportROM",supportROM);
             formData.append("downloads",downloads);
             formData.append("cate1",cate1);
             formData.append("cate2",cate2);
             formData.append("cate3",cate3);
             formData.append("desc",desc);
             formData.append("fileName",fileName);
             formData.append("states",states);
             **/
            $.ajax({
                url: "/AppManageSys/app/addandupload",
                data: arr,
                dataType: "JSON",
                type: "POST",
                success: function (data) {
                    if (data == 'ok') {
                        var index1 = layer.msg('数据保存成功', {icon: 16, time: false, shade: 0.5});
                        layer.close(index);
                        layer.close(index1);
                        window.parent.location.href = "/AppManageSys/app/dev_list";
                    } else {
                        var index2 = layer.msg('数据保存失败', {icon: 16, time: false, shade: 0.5});
                        layer.close(index2);
                    }
                }

            });
            return false;
        })

    });
</script>

</body>

</html>